<?php
/**
 * Created by PhpStorm.
 * User: ASUS
 * Date: 2016/12/27
 * Time: 21:38*/
//操作数据库
require dirname(__FILE__).'/dbconfig.php';//引入配置文件
class db{
    public $conn = null;
    function __construct($config)
    {
        $this->conn = mysqli_connect($config['host'],$config['username'],$config['password']) or die(mysqli_error($this->conn));//连接数据库
        mysqli_select_db($this->conn,$config['database']) or die(mysqli_error($this->conn));//选择数据库
        //mysqli_query("set names".$config['charset']) or die(mysqli_error());//设置编码
    }
    //
    public function getResult($sql){
        $resource = mysqli_query($this->conn,$sql) or die(mysqli_error($this->conn));//查询SQL语句
       // var_dump($resource);
        $res = array();
        $row = mysqli_fetch_assoc($resource);
        while($row!=false){
            $res[] = $row;
           // var_dump($res);exit;
        }
        return $res;
        mysqli_close($this->conn);

    }
    //
    public function getDateByGrade($grade){
        $sql = "select username,score,class from user where grade ='.$grade.'order by score desc";
        $res = $this->getResult($sql);
        return $res;

    }
}